from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#
# chrome_options = Options()
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--no-sandbox')
# # path是自己浏览器的文件路径
# path=r"C:\Program Files\Google\Chrome\Application\chrome.exe"
# chrome_options.binary_location = path
#
# browser = webdriver.Chrome(chrome_options=chrome_options)
#
# url = 'https://www.baidu.com/'
# browser.get(url)

#封装的handless

def share_browser():
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    # path是自己浏览器的文件路径
    path=r"C:\Program Files\Google\Chrome\Application\chrome.exe"
    chrome_options.binary_location = path
    browser = webdriver.Chrome(chrome_options=chrome_options)
    return browser

browser = share_browser()
url='https://www.baidu.com'
browser.get(url)
